#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/4/26 16:14
   @File: redisUtil.py
"""
import json

import redis

from DataTest.env import Env


class redisUtil():
    def __init__(self, ip, password='neikong@5', port=6379, db=0,**kwargs):
        self.ip = ip
        self.password = password
        self.port = port
        self.db = db
    def conn(self):
        pool = redis.ConnectionPool(host=self.ip, port=self.port, password=self.password, db=self.db)
        return redis.Redis(connection_pool=pool)
"""
删除指标
"""
def deleteRedis(keyWord,env=None):
    env=Env(env)
    redisIp=env.redis
    conn = redisUtil(redisIp).conn()
    key = 'hsrcm-rcce-monitorId:standard:'+keyWord
    conn.delete(key)

def addAccountIdRedis(keyWord,env=None):
    env=Env(env)
    redisIp=env.redis
    conn = redisUtil(redisIp).conn()
    key = 'hsrcm-permission:admin'
    permission=eval(conn.get(key).decode())
    if keyWord not in permission['permissions']['account']:
        permission['permissions']['account'].append(keyWord)
        conn.set(key,json.dumps(permission).encode())

if __name__ == '__main__':
    addAccountIdRedis('123',env='dm')
